package com.playball.lottery.frm.buyhall;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import com.playball.lottery.ApplicationData;
import com.playball.lottery.R;
import com.playball.lottery.customview.ShowTipDialog;
import com.playball.lottery.customview.segmentcontrol.SegmentControl;
import com.playball.lottery.customview.segmentcontrol.SegmentControl.OnSegmentControlClickListener;
import com.playball.lottery.frm.help.CaiPiaoHelp;
import com.playball.lottery.frm.yhzx.BetRecordActivity;
import com.playball.lottery.frm.yhzx.LoginActivity;
import com.playball.lottery.frm.yhzx.ZhRecordActivity;
import com.playball.lottery.nt.GetRequestParams;
import com.playball.lottery.util.ConvertJsonToList;
import com.playball.lottery.util.DateUtil;
import com.playball.lottery.util.DefConstants;
import com.playball.lottery.util.LotConstants;
import com.playball.lottery.util.MyPreference;
import com.playball.lottery.util.SysApplication;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.media.MediaBrowserCompat.MediaItem.Flags;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.LinearLayout.LayoutParams;

public class SixFuckActivity extends Activity implements Serializable, DefConstants {

	private Boolean ifbacklist;
	private PopupWindow m_popupWindow;
	private int lotID;
	private String issueID;
	private String issueName;
	private long endTime; // 剩余时间
	private String strssqEndTime;// 截止时间
	private String strPlayType;
	private int playTypeId;

	TextView buy_ssqxh_TextView01;// 期号
	TextView buy_ssqxh_TextView02;// 截至日期

	// ArrayList<Map<String, Object>> ball_1_49 = new
	// ArrayList<Map<String,Object>>();
	// ArrayList<Map<String, Object>> ball1_t1_t17 = new
	// ArrayList<Map<String,Object>>();
	boolean[] ball_1_49 = { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false,
			false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false,
			false, false, false, false, false, false, false, false, false, false };
	boolean[] ball1_t1_t17 = { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false };
	boolean[] ball1_zm_t1_t4 = { false, false, false, false };
	boolean[] ball_zmt_zmt1_zmt17 = { false, false,false, false,false, false,false, false,false, false,false, false,false};
	boolean[] ball_tmsx_tmsx1_12 = { false, false,false, false,false, false,false, false,false, false,false, false};
	
	private Button buy_ssqxh_Button05;
	
	View view_six_ball1_49, view_six_ball_zm_t1_t4, view_six_ballt1_t17, view_six_ball_zt1_zt17,view_six_ball_tmsx1_tmsx12;
	SegmentControl sc_zt;
	View view_lm_play_choose,view_sxl_play_choose,view_money;
	EditText et_money;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.layout_sixfuck);
		SysApplication.getInstance().addActivity(this);
		TitleBar();
		playTypeId = 9601;
		strPlayType = "特码";
		Intent intent = getIntent();
		lotID = LOT_ID_LHC;
		issueID = intent.getStringExtra("IssueID");
		issueName = intent.getStringExtra("IssueName");
		endTime = intent.getLongExtra("EndTime", 0);
		strssqEndTime = intent.getStringExtra("strssqEndTime");
		ifbacklist = intent.getBooleanExtra("ifbacklist", false);
		LayoutInflater inflater = LayoutInflater.from(SixFuckActivity.this);
		menutypeview = inflater.inflate(R.layout.six_fuck_play_top, null);
		view_lm_play_choose = findViewById(R.id.view_lm_play_choose);
		view_sxl_play_choose = findViewById(R.id.view_sxl_play_choose);
		view_money = findViewById(R.id.view_money);
		et_money = (EditText) findViewById(R.id.et_item);
		
		buy_ssqxh_TextView01 = (TextView) findViewById(R.id.buy_ssqxh_TextView01);
		buy_ssqxh_TextView02 = (TextView) findViewById(R.id.buy_ssqxh_TextView02);
		buy_ssqxh_TextView02.setText("--------------");
		view_six_ball1_49 = findViewById(R.id.view_six_ball1_49);
		view_six_ball_zm_t1_t4 = findViewById(R.id.view_six_ball_zm_t1_t4);
		view_six_ballt1_t17 = findViewById(R.id.view_six_ballt1_t17);
		view_six_ball_zt1_zt17 = findViewById(R.id.view_six_ball_zt1_zt17);
		view_six_ball_tmsx1_tmsx12 = findViewById(R.id.view_six_ball_tmsx1_tmsx12);
		buy_ssqxh_Button05 = (Button) findViewById(R.id.buy_ssqxh_Button05);
		// 确认选择，跳转至SsqxhlbActivity.class
		buy_ssqxh_Button05.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				goXhlbSubmit();
			}
		});
		
		handler.postDelayed(runnable, 1000);
		Button buy_ssqxh_Buttondel = (Button) findViewById(R.id.buy_ssqxh_Buttondel);
		// 清空选择
		buy_ssqxh_Buttondel.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				clearSelect();
			}
		});
		sc_zt = (SegmentControl) findViewById(R.id.sc_zt);
		sc_zt_play_index = 1;
		sc_zt.setSelectedIndex(sc_zt_play_index-1);
		sc_zt.setOnSegmentControlClickListener(new OnSegmentControlClickListener() {
			@Override
			public void onSegmentControlClick(int index) {
				sc_zt_play_index = 1+index;
				for (int i = 0; i < ball_zmt_zmt1_zmt17.length; i++) {
					if(ball_zmt_zmt1_zmt17[i] == true){
						ball_zmt_zmt1_zmt17[i] = false;
						((Button) findViewById(i + R.id.six_zt1)).setSelected(false);
					}
				}
				for (int i = 0; i < ball_1_49.length; i++) {
					if (ball_1_49[i] == true) {
						ball_1_49[i] = false;
						((Button) findViewById(i + R.id.six_ball01)).setSelected(false);
					}
				}
			}
		});
		setOrderField(R.id.buy_six_m_tm);
		
		
		
		PLAsyncLoader task = new PLAsyncLoader();
		String[] parms = new String[2];
		parms[0] = "10313";
		JSONObject jsob = new JSONObject();
		parms[1] = jsob.toString();
		task.execute(parms);
		
	}
	private int sc_zt_play_index;
	private int sc_lm_play_index;
	private int sc_sxl_play_index;

	protected void goXhlbSubmit() {
		if (!checkUserLogin()) {
			Toast.makeText(SixFuckActivity.this, "您为登录，请先登录！", Toast.LENGTH_SHORT).show();
			Intent intent = new Intent(SixFuckActivity.this, LoginActivity.class);
			startActivityForResult(intent, REQ_CODE_BUY_LOGIN);
			return;
		}
		Intent intent = new Intent(SixFuckActivity.this, SixFuckBetActivity.class);
		intent.putExtra("pl", pl);
		if (playTypeId == 9601) {// 特码
			boolean isJump = false;
			for (int i = 0; i < ball1_t1_t17.length; i++) {
				if (ball1_t1_t17[i] == true) {
					isJump = true;
					break;
				}
			}
			for (int i = 0; i < ball_1_49.length; i++) {
				if (ball_1_49[i] == true) {
					isJump = true;
					break;
				}
			}
			if (isJump == false) {
				Toast.makeText(SixFuckActivity.this, "请选择号码", Toast.LENGTH_SHORT).show();
			} else {
				intent.putExtra("bet_ball_1_49", ball_1_49);
				intent.putExtra("bet_ball1_t1_t17", ball1_t1_t17);
				intent.putExtra("LotID", lotID);
				intent.putExtra("IssueID", issueID);
				intent.putExtra("IssueName", issueName);
				intent.putExtra("PlayTypeId", playTypeId);
				intent.putExtra("strPlayType", strPlayType);
				SixFuckActivity.this.startActivityForResult(intent, REQ_CODE_BUYMAIN);// (intent);
				finish();
			}
		} else if (playTypeId == 9602) {// 正码
			boolean isJump = false;
			for (int i = 0; i < ball1_zm_t1_t4.length; i++) {
				if (ball1_zm_t1_t4[i] == true) {
					isJump = true;
					break;
				}
			}
			for (int i = 0; i < ball_1_49.length; i++) {
				if (ball_1_49[i] == true) {
					isJump = true;
					break;
				}
			}
			if (isJump == false) {
				Toast.makeText(SixFuckActivity.this, "请选择号码", Toast.LENGTH_SHORT).show();
			} else {
				intent.putExtra("bet_ball_1_49", ball_1_49);
				intent.putExtra("bet_ball1_zm_t1_t4", ball1_zm_t1_t4);
				intent.putExtra("LotID", lotID);
				intent.putExtra("IssueID", issueID);
				intent.putExtra("IssueName", issueName);
				intent.putExtra("PlayTypeId", playTypeId);
				intent.putExtra("strPlayType", strPlayType);
				SixFuckActivity.this.startActivityForResult(intent, REQ_CODE_BUYMAIN);// (intent);
				finish();
			}
		}else if (playTypeId == 9603) {// 正码特
			boolean isJump = false;
			for (int i = 0; i < ball_zmt_zmt1_zmt17.length; i++) {
				if (ball_zmt_zmt1_zmt17[i] == true) {
					isJump = true;
					break;
				}
			}
			for (int i = 0; i < ball_1_49.length; i++) {
				if (ball_1_49[i] == true) {
					isJump = true;
					break;
				}
			}
			if (isJump == false) {
				Toast.makeText(SixFuckActivity.this, "请选择号码", Toast.LENGTH_SHORT).show();
			} else {
				intent.putExtra("bet_ball_1_49", ball_1_49);
				intent.putExtra("bet_ball_zmt_zmt1_zmt17", ball_zmt_zmt1_zmt17);
				intent.putExtra("LotID", lotID);
				intent.putExtra("IssueID", issueID);
				intent.putExtra("IssueName", issueName);
				intent.putExtra("PlayTypeId", playTypeId);
				intent.putExtra("strPlayType", strPlayType);
				intent.putExtra("sc_zt_play_index", sc_zt_play_index);
				SixFuckActivity.this.startActivityForResult(intent, REQ_CODE_BUYMAIN);// (intent);
				finish();
			}
		}else if (playTypeId == 9604) {// 特码生肖
			boolean isJump = false;
			for (int i = 0; i < ball_tmsx_tmsx1_12.length; i++) {
				if (ball_tmsx_tmsx1_12[i] == true) {
					isJump = true;
					break;
				}
			}
			if (isJump == false) {
				Toast.makeText(SixFuckActivity.this, "请选择号码", Toast.LENGTH_SHORT).show();
			} else {
				intent.putExtra("bet_ball_tmsx_tmsx1_12", ball_tmsx_tmsx1_12);
				intent.putExtra("LotID", lotID);
				intent.putExtra("IssueID", issueID);
				intent.putExtra("IssueName", issueName);
				intent.putExtra("PlayTypeId", playTypeId);
				intent.putExtra("strPlayType", strPlayType);
				SixFuckActivity.this.startActivityForResult(intent, REQ_CODE_BUYMAIN);// (intent);
				finish();
			}
		}else if(playTypeId == 9605 || playTypeId == 9606){//连码、生肖连
			goLiianAAAAA();
		}
	}
	String[] dyn;
	private void goLiianAAAAA() {
		
		if(et_money.getText().toString().isEmpty() || Integer.parseInt(et_money.getText().toString()) < 2){
			Toast.makeText(SixFuckActivity.this, "请输入投注金额，最少2彩豆", Toast.LENGTH_LONG).show();
			buy_ssqxh_Button05.setEnabled(true);
			return;
		}
		buy_ssqxh_Button05.setEnabled(false);
		if(playTypeId == 9606){//连码
			String number = "";
			String payname = "";
			int num = 0;
			for(int i=0;i<ball_1_49.length;i++){
				if(ball_1_49[i] == true){
					number = number + (i+1)+",";
					num = num + 1;
				}
			}
			if(sc_lm_play_index == 1){
				payname = "lm3qz";
				if(num != 3){
					Toast.makeText(SixFuckActivity.this, "三全中必须且只能选择三个号码", Toast.LENGTH_LONG).show();
					buy_ssqxh_Button05.setEnabled(true);
					return;
				}
			}else if(sc_lm_play_index == 2){
				payname = "lm3z2";
				if(num != 3){
					Toast.makeText(SixFuckActivity.this, "三中二必须且只能选择三个号码", Toast.LENGTH_LONG).show();
					buy_ssqxh_Button05.setEnabled(true);
					return;
				}
			}else if(sc_lm_play_index == 3){
				payname = "lm2qz";
				if(num != 2){
					Toast.makeText(SixFuckActivity.this, "二全中必须且只能选择两个号码", Toast.LENGTH_LONG).show();
					buy_ssqxh_Button05.setEnabled(true);
					return;
				}
			}else if(sc_lm_play_index == 4){
				payname = "lm2zt";
				if(num != 2){
					Toast.makeText(SixFuckActivity.this, "二中特必须且只能选择两个号码", Toast.LENGTH_LONG).show();
					buy_ssqxh_Button05.setEnabled(true);
					return;
				}
			}else if(sc_lm_play_index == 5){
				payname = "lmtc";
				if(num != 2){
					Toast.makeText(SixFuckActivity.this, "特串必须且只能选择2个号码", Toast.LENGTH_LONG).show();
					buy_ssqxh_Button05.setEnabled(true);
					return;
				}
			}else if(sc_lm_play_index == 6){
				payname = "lm4z1";
				if(num != 4){
					Toast.makeText(SixFuckActivity.this, "四中一必须且只能选择四个号码", Toast.LENGTH_LONG).show();
					buy_ssqxh_Button05.setEnabled(true);
					return;
				}
			}
			number = number.substring(0, number.length()-1);
			number = number + "="+et_money.getText().toString();
			number = number + "|"+payname;
			List<Map<String, Object>> numArr = new ArrayList<Map<String, Object>>();
			Map<String, Object> map = new HashMap<String, Object>();
			System.out.println(number);
			map.put("number", number);
			map.put("playid", playTypeId);
			numArr.add(map);
			AsyncLoaderBuy task = new AsyncLoaderBuy();
			dyn = new String[2];
			JSONObject params = new JSONObject();
			try {
				JSONArray array1 = new JSONArray();
				for (int i = 0; i < numArr.size(); i++) {
					JSONObject o = new JSONObject(numArr.get(i));
					array1.put(o);
				}
				params.put("SchemeType", 1);// 方案类型 1自购，2合买，3保存 1
				params.put("BetType", 1);// 投注类型 1选号投注 2单式上传 3先发后传 1
				params.put("BonusScale", 0);
				params.put("AssureShare", 0);
				params.put("Description", "");
				params.put("OpenUserList", "");
				params.put("SecrecyLevel", 4);
				params.put("BuyShare", et_money.getText().toString());
				params.put("Multiple", 1);
				params.put("LotteryID", lotID);
				params.put("IssueID", issueID);
				params.put("IssueName", issueName);
				params.put("Number", array1);
				params.put("Money", et_money.getText().toString());
			} catch (JSONException ex) {
				Log.e("error", ex.toString());
			}
			dyn[0] = params.toString();
			dyn[1] = "207";// 200
			task.execute(dyn);
		}else if(playTypeId == 9605){//生肖连
			String number = "";
			String payname = "";
			int num = 0;
			for(int i=0;i<ball_tmsx_tmsx1_12.length;i++){
				if(ball_tmsx_tmsx1_12[i] == true){
					number = number + (i+1)+",";
					num = num + 1;
				}
			}
			if(sc_sxl_play_index == 1){
				payname = "sxl2xlz";
				if(num != 2){
					Toast.makeText(SixFuckActivity.this, "二肖连中必须且只能选择二个号码", Toast.LENGTH_LONG).show();
					buy_ssqxh_Button05.setEnabled(true);
					return;
				}
			}else if(sc_sxl_play_index == 2){
				payname = "sxl3xlz";
				if(num != 3){
					Toast.makeText(SixFuckActivity.this, "三肖连中必须且只能选择三个号码", Toast.LENGTH_LONG).show();
					buy_ssqxh_Button05.setEnabled(true);
					return;
				}
			}else if(sc_sxl_play_index == 3){
				payname = "sxl4xlz";
				if(num != 4){
					Toast.makeText(SixFuckActivity.this, "四肖连中必须且只能选择四个号码", Toast.LENGTH_LONG).show();
					buy_ssqxh_Button05.setEnabled(true);
					return;
				}
			}else if(sc_sxl_play_index == 4){
				payname = "sxl5xlz";
				if(num != 5){
					Toast.makeText(SixFuckActivity.this, "五肖连中必须且只能选择五个号码", Toast.LENGTH_LONG).show();
					buy_ssqxh_Button05.setEnabled(true);
					return;
				}
			}else if(sc_sxl_play_index == 5){
				payname = "sxl2xlbz";
				if(num != 2){
					Toast.makeText(SixFuckActivity.this, "二肖连不中必须且只能选择2个号码", Toast.LENGTH_LONG).show();
					buy_ssqxh_Button05.setEnabled(true);
					return;
				}
			}else if(sc_sxl_play_index == 6){
				payname = "sxl3xlbz";
				if(num != 3){
					Toast.makeText(SixFuckActivity.this, "三肖连不中必须且只能选择三四个号码", Toast.LENGTH_LONG).show();
					buy_ssqxh_Button05.setEnabled(true);
					return;
				}
			}else if(sc_sxl_play_index == 7){
				payname = "sxl4xlbz";
				if(num != 4){
					Toast.makeText(SixFuckActivity.this, "四肖连不中必须且只能选择四个号码", Toast.LENGTH_LONG).show();
					buy_ssqxh_Button05.setEnabled(true);
					return;
				}
			}else if(sc_sxl_play_index == 8){
				payname = "sxl1xlz";
				if(num < 1){
					Toast.makeText(SixFuckActivity.this, "一肖最少需要选择一个号码", Toast.LENGTH_LONG).show();
					buy_ssqxh_Button05.setEnabled(true);
					return;
				}
			}
			number = number.substring(0, number.length()-1);
			number = number + "="+et_money.getText().toString();
			number = number + "|"+payname;
			List<Map<String, Object>> numArr = new ArrayList<Map<String, Object>>();
			Map<String, Object> map = new HashMap<String, Object>();
			System.out.println(number);
			map.put("number", number);
			map.put("playid", playTypeId);
			numArr.add(map);
			AsyncLoaderBuy task = new AsyncLoaderBuy();
			dyn = new String[2];
			JSONObject params = new JSONObject();
			try {
				JSONArray array1 = new JSONArray();
				for (int i = 0; i < numArr.size(); i++) {
					JSONObject o = new JSONObject(numArr.get(i));
					array1.put(o);
				}
				params.put("SchemeType", 1);// 方案类型 1自购，2合买，3保存 1
				params.put("BetType", 1);// 投注类型 1选号投注 2单式上传 3先发后传 1
				params.put("BonusScale", 0);
				params.put("AssureShare", 0);
				params.put("Description", "");
				params.put("OpenUserList", "");
				params.put("SecrecyLevel", 4);
				params.put("BuyShare", et_money.getText().toString());
				params.put("Multiple", 1);
				params.put("LotteryID", lotID);
				params.put("IssueID", issueID);
				params.put("IssueName", issueName);
				params.put("Number", array1);
				params.put("Money", et_money.getText().toString());
			} catch (JSONException ex) {
				Log.e("error", ex.toString());
			}
			dyn[0] = params.toString();
			dyn[1] = "207";// 200
			task.execute(dyn);
		
		}
		
		
		
	}
	public void redBallClick(View view) {
		int id = view.getId() - R.id.six_ball01;
		System.out.println(id);
		if (((Button) view).isSelected()) {
			((Button) view).setSelected(false);
			ball_1_49[id] = false;
		} else {
			((Button) view).setSelected(true);
			ball_1_49[id] = true;
		}

	}

	public void blueBallClick(View view) {

	}

	public void zmClick(View view) {
		int id = view.getId() - R.id.six_zm_t1;
		System.out.println(id);
		if (((Button) view).isSelected()) {
			((Button) view).setSelected(false);
			ball1_zm_t1_t4[id] = false;
		} else {
			((Button) view).setSelected(true);
			ball1_zm_t1_t4[id] = true;
		}
	}

	public void tBallClick(View view) {
		int id = view.getId() - R.id.six_t1;
		if (((Button) view).isSelected()) {
			((Button) view).setSelected(false);
			ball1_t1_t17[id] = false;
		} else {
			((Button) view).setSelected(true);
			ball1_t1_t17[id] = true;
		}
	}
	
	public void zmtBallClick(View view) {
		int id = view.getId() - R.id.six_zt1;
		if (((Button) view).isSelected()) {
			((Button) view).setSelected(false);
			ball_zmt_zmt1_zmt17[id] = false;
		} else {
			((Button) view).setSelected(true);
			ball_zmt_zmt1_zmt17[id] = true;
		}
	}

	public void tmsxBallClick(View view) {
		int id = view.getId() - R.id.six_tmsx1;
		if (((Button) view).isSelected()) {
			((Button) view).setSelected(false);
			ball_tmsx_tmsx1_12[id] = false;
		} else {
			((Button) view).setSelected(true);
			ball_tmsx_tmsx1_12[id] = true;
		}
	}

	public void lm_play_chooseClick(View view) {
		findViewById(R.id.buy_six_m_lm_3qz).setSelected(false);
		findViewById(R.id.buy_six_m_lm_3z2).setSelected(false);
		findViewById(R.id.buy_six_m_lm_2qz).setSelected(false);
		findViewById(R.id.buy_six_m_lm_2zt).setSelected(false);
		findViewById(R.id.buy_six_m_lm_tc).setSelected(false);
		findViewById(R.id.buy_six_m_lm_4z1).setSelected(false);
		et_money.setText("");
		view.setSelected(true);
		if(view.getId() == R.id.buy_six_m_lm_3qz){
			sc_lm_play_index = 1;
		}else if(view.getId() == R.id.buy_six_m_lm_3z2){
			sc_lm_play_index = 2;
		}else if(view.getId() == R.id.buy_six_m_lm_2qz){
			sc_lm_play_index = 3;
		}else if(view.getId() == R.id.buy_six_m_lm_2zt){
			sc_lm_play_index = 4;
		}else if(view.getId() == R.id.buy_six_m_lm_tc){
			sc_lm_play_index = 5;
		}else if(view.getId() == R.id.buy_six_m_lm_4z1){
			sc_lm_play_index = 6;
		}
		setBtn_lm_play_choose(sc_lm_play_index);
	}
	
	void setBtn_lm_play_choose(int playid){
		for (int i = 0; i < ball_1_49.length; i++) {
			if (ball_1_49[i] == true) {
				ball_1_49[i] = false;
				((Button) findViewById(i + R.id.six_ball01)).setSelected(false);
			}
		}
		findViewById(R.id.buy_six_m_lm_3qz).setSelected(false);
		findViewById(R.id.buy_six_m_lm_3z2).setSelected(false);
		findViewById(R.id.buy_six_m_lm_2qz).setSelected(false);
		findViewById(R.id.buy_six_m_lm_2zt).setSelected(false);
		findViewById(R.id.buy_six_m_lm_tc).setSelected(false);
		findViewById(R.id.buy_six_m_lm_4z1).setSelected(false);
		et_money.setText("");
		if(playid == 1){
			findViewById(R.id.buy_six_m_lm_3qz).setSelected(true);
		}else if(playid == 2){
			findViewById(R.id.buy_six_m_lm_3z2).setSelected(true);
		}else if(playid == 3){
			findViewById(R.id.buy_six_m_lm_2qz).setSelected(true);
		}else if(playid == 4){
			findViewById(R.id.buy_six_m_lm_2zt).setSelected(true);
		}else if(playid == 5){
			findViewById(R.id.buy_six_m_lm_tc).setSelected(true);
		}else if(playid == 6){
			findViewById(R.id.buy_six_m_lm_4z1).setSelected(true);
		}
	}
	
	public void sxl_play_chooseClick(View view) {
		findViewById(R.id.buy_six_m_sxl_2xlbz).setSelected(false);
		findViewById(R.id.buy_six_m_sxl_2xlz).setSelected(false);
		findViewById(R.id.buy_six_m_sxl_3xlbz).setSelected(false);
		findViewById(R.id.buy_six_m_sxl_3xlz).setSelected(false);
		findViewById(R.id.buy_six_m_sxl_4xlbz).setSelected(false);
		findViewById(R.id.buy_six_m_sxl_4xlz).setSelected(false);
		findViewById(R.id.buy_six_m_sxl_5xlz).setSelected(false);
		findViewById(R.id.buy_six_m_sxl_1xlz).setSelected(false);
		et_money.setText("");
		view.setSelected(true);
		if(view.getId() == R.id.buy_six_m_sxl_2xlz){
			sc_sxl_play_index = 1;
		}else if(view.getId() == R.id.buy_six_m_sxl_3xlz){
			sc_sxl_play_index = 2;
		}else if(view.getId() == R.id.buy_six_m_sxl_4xlz){
			sc_sxl_play_index = 3;
		}else if(view.getId() == R.id.buy_six_m_sxl_5xlz){
			sc_sxl_play_index = 4;
		}else if(view.getId() == R.id.buy_six_m_sxl_2xlbz){
			sc_sxl_play_index = 5;
		}else if(view.getId() == R.id.buy_six_m_sxl_3xlbz){
			sc_sxl_play_index = 6;
		}else if(view.getId() == R.id.buy_six_m_sxl_4xlbz){
			sc_sxl_play_index = 7;
		}else if(view.getId() == R.id.buy_six_m_sxl_1xlz){
			sc_sxl_play_index = 8;
		}
		setBtn_sxl_play_choose(sc_sxl_play_index);
	}
	
	void setBtn_sxl_play_choose(int playid){
		for (int i = 0; i < ball_tmsx_tmsx1_12.length; i++) {
			if(ball_tmsx_tmsx1_12[i] == true){
				ball_tmsx_tmsx1_12[i] = false;
				((Button) findViewById(i + R.id.six_tmsx1)).setSelected(false);
			}
		}
		findViewById(R.id.buy_six_m_sxl_2xlbz).setSelected(false);
		findViewById(R.id.buy_six_m_sxl_2xlz).setSelected(false);
		findViewById(R.id.buy_six_m_sxl_3xlbz).setSelected(false);
		findViewById(R.id.buy_six_m_sxl_3xlz).setSelected(false);
		findViewById(R.id.buy_six_m_sxl_4xlbz).setSelected(false);
		findViewById(R.id.buy_six_m_sxl_4xlz).setSelected(false);
		findViewById(R.id.buy_six_m_sxl_5xlz).setSelected(false);
		findViewById(R.id.buy_six_m_sxl_1xlz).setSelected(false);
		et_money.setText("");
		if(playid == 1){
			findViewById(R.id.buy_six_m_sxl_2xlz).setSelected(true);
		}else if(playid == 2){
			findViewById(R.id.buy_six_m_sxl_3xlz).setSelected(true);
		}else if(playid == 3){
			findViewById(R.id.buy_six_m_sxl_4xlz).setSelected(true);
		}else if(playid == 4){
			findViewById(R.id.buy_six_m_sxl_5xlz).setSelected(true);
		}else if(playid == 5){
			findViewById(R.id.buy_six_m_sxl_2xlbz).setSelected(true);
		}else if(playid == 6){
			findViewById(R.id.buy_six_m_sxl_3xlbz).setSelected(true);
		}else if(playid == 7){
			findViewById(R.id.buy_six_m_sxl_4xlbz).setSelected(true);
		}else if(playid == 8){
			findViewById(R.id.buy_six_m_sxl_1xlz).setSelected(true);
		}
	}
	
	/**
	 * 菜单玩法按钮事件
	 * 
	 * @param btnId
	 */
	private void setBtnOnClick(final int btnId) {
		Button btn = (Button) menutypeview.findViewById(btnId);
		btn.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				menu_popupWindow.dismiss();
				setOrderField(btnId);
			}
		});
	}

	protected void clearSelect() {
//		if (playTypeId == 9601) {// 特码
			for (int i = 0; i < ball1_t1_t17.length; i++) {
				if (ball1_t1_t17[i] == true) {
					ball1_t1_t17[i] = false;
					((Button) findViewById(i + R.id.six_t1)).setSelected(false);
				}
			}
			for (int i = 0; i < ball_1_49.length; i++) {
				if (ball_1_49[i] == true) {
					ball_1_49[i] = false;
					((Button) findViewById(i + R.id.six_ball01)).setSelected(false);
				}
			}
			for (int i = 0; i < ball1_zm_t1_t4.length; i++) {
				if(ball1_zm_t1_t4[i] == true){
					ball1_zm_t1_t4[i] = false;
					((Button) findViewById(i + R.id.six_zm_t1)).setSelected(false);
				}
				
			}
			for (int i = 0; i < ball_zmt_zmt1_zmt17.length; i++) {
				if(ball_zmt_zmt1_zmt17[i] == true){
					ball_zmt_zmt1_zmt17[i] = false;
					System.out.println("111111111111");
					((Button) findViewById(i + R.id.six_zt1)).setSelected(false);
				}
			}
		for (int i = 0; i < ball_tmsx_tmsx1_12.length; i++) {
			if(ball_tmsx_tmsx1_12[i] == true){
				ball_tmsx_tmsx1_12[i] = false;
				((Button) findViewById(i + R.id.six_tmsx1)).setSelected(false);
			}
		}
//		}
	}
	
	List<Map<String, Object>> plList;
	private String getPL(String string) {
		String res = "0.00";
		for(Map<String, Object>item:plList){
			if(item.get("Type").toString().equals(string)){
				DecimalFormat decimalFormat=new DecimalFormat(".00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
				res = decimalFormat.format(Float.parseFloat(item.get("PL").toString()));
				return res;
			}
		}
		return res;
	}
	
	/**
	 * 获取玩法及改变按钮背景
	 * 
	 * @param btnId
	 */
	public void setOrderField(int btnId) {
		clearSelect();
		// 恢复默认
		((Button) menutypeview.findViewById(R.id.buy_six_m_bb)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_six_m_gg)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_six_m_lm)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_six_m_sxl)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_six_m_tm)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_six_m_wsl)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_six_m_yx)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_six_m_yx_hx)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_six_m_zm)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_six_m_zmt)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_six_m_tmsx)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_six_m_qbz)).setSelected(false);
		buy_ssqxh_Button05.setText("确定");
		view_six_ball1_49.setVisibility(View.GONE);
		view_six_ball_zm_t1_t4.setVisibility(View.GONE);
		view_six_ballt1_t17.setVisibility(View.GONE);
		view_six_ball_zt1_zt17.setVisibility(View.GONE);
		view_six_ball_tmsx1_tmsx12.setVisibility(View.GONE);
		view_lm_play_choose.setVisibility(View.GONE);
		view_sxl_play_choose.setVisibility(View.GONE);
		view_money.setVisibility(View.GONE);
		sc_zt.setVisibility(View.INVISIBLE);
		sc_zt_play_index = 1;
		switch (btnId) {
		case R.id.buy_six_m_tm:
			playTypeId = 9601;
			strPlayType = "特码";
			((Button) menutypeview.findViewById(R.id.buy_six_m_tm)).setSelected(true);
			view_six_ball1_49.setVisibility(View.VISIBLE);
			view_six_ballt1_t17.setVisibility(View.VISIBLE);
			break;
		case R.id.buy_six_m_zm:
			playTypeId = 9602;
			strPlayType = "正码";
			view_six_ball1_49.setVisibility(View.VISIBLE);
			view_six_ball_zm_t1_t4.setVisibility(View.VISIBLE);
			((Button) menutypeview.findViewById(R.id.buy_six_m_zm)).setSelected(true);
			break;
		case R.id.buy_six_m_zmt:
			playTypeId = 9603;
			strPlayType = "正码特";
			((Button) menutypeview.findViewById(R.id.buy_six_m_zmt)).setSelected(true);
			sc_zt.setVisibility(View.VISIBLE);
			view_six_ball1_49.setVisibility(View.VISIBLE);
			view_six_ball_zt1_zt17.setVisibility(View.VISIBLE);
			sc_zt_play_index = 1;
			sc_zt.setSelectedIndex(sc_zt_play_index-1);
			break;
		case R.id.buy_six_m_tmsx:
			playTypeId = 9604;
			strPlayType = "特码生肖";
			((Button) menutypeview.findViewById(R.id.buy_six_m_tmsx)).setSelected(true);
			view_six_ball_tmsx1_tmsx12.setVisibility(View.VISIBLE);
			break;
		case R.id.buy_six_m_lm:
			buy_ssqxh_Button05.setText("付款");
			playTypeId = 9606;
			strPlayType = "连码";
			sc_lm_play_index = 1;
			view_money.setVisibility(View.VISIBLE);
			setBtn_lm_play_choose(sc_lm_play_index);
			view_six_ball1_49.setVisibility(View.VISIBLE);
			view_lm_play_choose.setVisibility(View.VISIBLE);
			((Button) menutypeview.findViewById(R.id.buy_six_m_lm)).setSelected(true);
			
			((Button)findViewById(R.id.buy_six_m_lm_3qz)).setText("三全中"+getPL("9606-lm3qz"));
			((Button)findViewById(R.id.buy_six_m_lm_3z2)).setText("三中二 中二"+getPL("9606-lm3z2")+"中三"+getPL("9606-lm3z3"));
			((Button)findViewById(R.id.buy_six_m_lm_2qz)).setText("二全中"+getPL("9606-lm2qz"));
			((Button)findViewById(R.id.buy_six_m_lm_2zt)).setText("二中特 中特"+getPL("9606-lm2ztzt")+" 中二"+getPL("9606-lm2ztz2"));
			((Button)findViewById(R.id.buy_six_m_lm_tc)).setText("特串"+getPL("9606-lmtc"));
			((Button)findViewById(R.id.buy_six_m_lm_4z1)).setText("四中一"+getPL("9606-lm4z1"));
			
			break;
		case R.id.buy_six_m_sxl:
			playTypeId = 9605;
			buy_ssqxh_Button05.setText("付款");
			strPlayType = "生肖连";
			sc_sxl_play_index = 1;
			setBtn_sxl_play_choose(sc_sxl_play_index);
			view_money.setVisibility(View.VISIBLE);
			view_sxl_play_choose.setVisibility(View.VISIBLE);
			((Button) menutypeview.findViewById(R.id.buy_six_m_sxl)).setSelected(true);
			view_six_ball_tmsx1_tmsx12.setVisibility(View.VISIBLE);
			
			((Button)findViewById(R.id.buy_six_m_sxl_2xlbz)).setText("二肖连不中"+getPL("9605-sxl2xlbz"));
			((Button)findViewById(R.id.buy_six_m_sxl_2xlz)).setText("二肖连中"+getPL("9605-sxl2xlz"));
			((Button)findViewById(R.id.buy_six_m_sxl_3xlbz)).setText("三肖连不中"+getPL("9605-sxl3xlbz"));
			((Button)findViewById(R.id.buy_six_m_sxl_3xlz)).setText("三肖连中"+getPL("9605-sxl3xlz"));
			((Button)findViewById(R.id.buy_six_m_sxl_4xlbz)).setText("四肖连不中"+getPL("9605-sxl4xlbz"));
			((Button)findViewById(R.id.buy_six_m_sxl_4xlz)).setText("四肖连中"+getPL("9605-sxl4xlz"));
			((Button)findViewById(R.id.buy_six_m_sxl_5xlz)).setText("五肖连中"+getPL("9605-sxl5xlz"));
			((Button)findViewById(R.id.buy_six_m_sxl_1xlz)).setText("一肖"+getPL("9605-sxl1xlz"));
			break;
		}
		top_title_tvplaytype.setText(strPlayType);
	}

	TextView top_title_tvplaytype;
	// TitleBar标题栏
	Button refres;
	/** 菜单弹出框 */
	private PopupWindow menu_popupWindow;
	/** 菜单弹出框 */
	private View menutypeview;

	public void TitleBar() {
		// Title信息(返回+Title)
		Button back = (Button) findViewById(R.id.top_title_back);
		back.getBackground().setAlpha(255);// 透明度0~255透明度值 ，值越小越透明
		back.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				onKeyDown(KeyEvent.KEYCODE_BACK, null);
			}
		});
		top_title_tvplaytype = (TextView) findViewById(R.id.top_title_tvplaytype);
		top_title_tvplaytype.setText(strPlayType);
		TextView info = (TextView) findViewById(R.id.top_title_info);
		info.setText("六合彩-");// R.string.fucai3d_name
		top_title_tvplaytype.setText(strPlayType);

		final LinearLayout buy_jclq_center_rl2 = (LinearLayout) findViewById(R.id.buy_jclq_center_rl2);
		buy_jclq_center_rl2.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// LayoutInflater inflater =
				// LayoutInflater.from(SixFuckActivity.this);
				// menutypeview = inflater.inflate(R.layout.six_fuck_play_top,
				// null);
				menu_popupWindow = new PopupWindow(menutypeview, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
				menu_popupWindow.setBackgroundDrawable(new BitmapDrawable());
				menu_popupWindow.setFocusable(true);
				menu_popupWindow.setTouchable(true);
				menu_popupWindow.setOutsideTouchable(false);
				menu_popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
				menu_popupWindow.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
				menu_popupWindow.showAtLocation(menutypeview, Gravity.CENTER | Gravity.TOP, 0, 0);
				menu_popupWindow.showAsDropDown(buy_jclq_center_rl2);
				menutypeview.setOnClickListener(new View.OnClickListener() {
					public void onClick(View v) {
						menu_popupWindow.dismiss();
					}
				});
				setBtnOnClick(R.id.buy_six_m_bb);
				setBtnOnClick(R.id.buy_six_m_gg);
				setBtnOnClick(R.id.buy_six_m_lm);
				setBtnOnClick(R.id.buy_six_m_sxl);
				setBtnOnClick(R.id.buy_six_m_tm);
				setBtnOnClick(R.id.buy_six_m_wsl);
				setBtnOnClick(R.id.buy_six_m_yx);
				setBtnOnClick(R.id.buy_six_m_yx_hx);
				setBtnOnClick(R.id.buy_six_m_zm);
				setBtnOnClick(R.id.buy_six_m_zmt);
				setBtnOnClick(R.id.buy_six_m_tmsx);
				setBtnOnClick(R.id.buy_six_m_qbz);
				if (strPlayType.equals("特码")) {
					((Button) menutypeview.findViewById(R.id.buy_six_m_tm)).setSelected(true);
				} else if (strPlayType.equals("正码")) {
					((Button) menutypeview.findViewById(R.id.buy_six_m_zm)).setSelected(true);
				} else if (strPlayType.equals("正码特")) {
					((Button) menutypeview.findViewById(R.id.buy_six_m_zmt)).setSelected(true);
				} else if (strPlayType.equals("连码")) {
					((Button) menutypeview.findViewById(R.id.buy_six_m_lm)).setSelected(true);
				} else if (strPlayType.equals("特码生肖")) {
					((Button) menutypeview.findViewById(R.id.buy_six_m_tmsx)).setSelected(true);
				} else if (strPlayType.equals("生肖连")) {
					((Button) menutypeview.findViewById(R.id.buy_six_m_sxl)).setSelected(true);
				}
			}
		});

		refres = (Button) findViewById(R.id.top_title_refres);
		refres.setBackgroundDrawable(null);
		refres.setText("帮助");
		refres.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				LayoutInflater inflater = LayoutInflater.from(SixFuckActivity.this);
				// 小目录框的设置
				View menuview = inflater.inflate(R.layout.public_menulink, null);
				m_popupWindow = new PopupWindow(menuview, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
				m_popupWindow.setBackgroundDrawable(new BitmapDrawable());
				m_popupWindow.setOutsideTouchable(true);
				m_popupWindow.showAtLocation(menuview, Gravity.RIGHT | Gravity.TOP, 0, 0);
				m_popupWindow.showAsDropDown(refres);
				menuview.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						m_popupWindow.dismiss();
					}
				});

				Button public_menulink_Button01 = (Button) menuview.findViewById(R.id.public_menulink_Button01);
				public_menulink_Button01.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						Intent intent;
						m_popupWindow.dismiss();
						if (checkUserLogin()) {
							Intent intent0 = new Intent();
							intent0.putExtra("lotID", LOT_ID_LHC);
							intent0.setClass(SixFuckActivity.this, BetRecordActivity.class);
							startActivity(intent0);
						} else {
							intent = new Intent(getApplicationContext(), LoginActivity.class);
							startActivityForResult(intent, REQ_CODE_SSQXH);
						}
					}
				});

				Button public_menulink_Button02 = (Button) menuview.findViewById(R.id.public_menulink_Button02);
				public_menulink_Button02.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						Intent intent;
						m_popupWindow.dismiss();
						if (checkUserLogin()) {
							intent = new Intent(getApplicationContext(), ZhRecordActivity.class);
							startActivity(intent);
						} else {
							intent = new Intent(getApplicationContext(), LoginActivity.class);
							startActivityForResult(intent, REQ_CODE_SSQXH);
						}
					}
				});
				Button public_menulink_Button03 = (Button) menuview.findViewById(R.id.public_menulink_Button03);
				public_menulink_Button03.setVisibility(View.GONE);
				public_menulink_Button03.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// m_popupWindow.dismiss();
						// Intent intent;
						// intent = new Intent(getApplicationContext(),
						// KjinfoListByType.class);
						// intent.putExtra("LottID", "96");
						// intent.putExtra("LottName",
						// getString(R.string.kjinfo_number_s_info02));
						// startActivity(intent);
					}
				});
				Button public_menulink_Button04 = (Button) menuview.findViewById(R.id.public_menulink_Button04);
				public_menulink_Button04.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						m_popupWindow.dismiss();
						Intent intent = new Intent(getApplicationContext(), CaiPiaoHelp.class);
						intent.putExtra("cp_title", "六合彩");
						intent.putExtra("cp_url", "lhc.htm");
						startActivity(intent);
					}
				});
			}
		});
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (m_popupWindow != null) {
			m_popupWindow.dismiss();
		}
		return super.onTouchEvent(event);
	}

	public boolean checkUserLogin() {
		if (!ApplicationData.getInstance().getLoginName().equals("") && !ApplicationData.getInstance().getLoginPwd().equals("")
				|| !ApplicationData.getInstance().getUserID().equals("")) {
			return true;
		} else {
			return false;
		}
	}

	// java.lang.SecurityException: getDeviceId: Neither user 10060 nor current
	// process has android.permission.READ_PHONE_STATE.

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if (m_popupWindow != null) {
				m_popupWindow.dismiss();
			}
			if (ifbacklist) {
				// Intent intent = new Intent();
				// intent.putExtra("list_ssqdto",
				// ApplicationData.getInstance().getList_ssqdto());
				// intent.putExtra("AllMoney",
				// ApplicationData.getInstance().getAll_ssqmoney());
				// intent.putExtra("LotID", lotID);
				// intent.putExtra("IssueID", issueID);
				// intent.putExtra("IssueName", issueName);
				// intent.setClass(SixFuckActivity.this, SsqxhlbActivity.class);
				// SixFuckActivity.this.startActivityForResult(intent,
				// REQ_CODE_BUYMAIN);// (intent);
			} else {
				// 停止监听
				ApplicationData.getInstance().initList();
			}
			this.finish();
			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onActivityResult(int, int,
	 * android.content.Intent)
	 */
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		if (resultCode == RESULT_OK) {
			if (requestCode == REQ_CODE_BUYMAIN) {
				onKeyDown(KeyEvent.KEYCODE_BACK, null);
			} else if (requestCode == REQ_CODE_BUY_LOGIN) {
				goXhlbSubmit();
			}
		}
	};

	@Override
	protected void onPause() {
		super.onPause();
	}

	@Override
	protected void onResume() {
		super.onResume();
		buy_ssqxh_Button05.setEnabled(true);
	}

	@Override
	protected void onDestroy() {
		handler.removeCallbacks(runnable);
		super.onDestroy();
	}

	@Override
	public void finish() {
		if (m_popupWindow != null) {
			m_popupWindow.dismiss();
		}
		super.finish();
		SysApplication.getInstance().removeActivity(this);
	};

	Handler handler = new Handler();
	// 倒计时
	Runnable runnable = new Runnable() {
		@Override
		public void run() {
			getCountDown(endTime--);
			handler.postDelayed(this, 1000);
		}
	};

	// 倒计时，时间转化
	private void getCountDown(long end) {
		if (end > 0) {
			String res = "";
			long temp = 0;
			long d = end / 86400;
			temp = end - (d * 86400);
			if (d > 0) {
				res += d + "天";
			}
			long h = temp / 3600;
			temp = temp - (h * 3600);
			if (d >= 0 && h > 0) {
				res += h + "时";
			}
			long m = temp / 60;
			temp = temp - (m * 60);
			if (d >= 0 && h >= 0 && m > 0) {
				res += m + "分";
			}
			long s = temp;
			res += s + "秒";
			buy_ssqxh_TextView02.setText(res);
			// buy_ssqxh_TextView02.setText(endTime+"");
		} else {
			buy_ssqxh_TextView02.setText("----------");
			if (getIssue) {
				getIssue = false;
				AsyncLoader task = new AsyncLoader();
				String[] parms = new String[2];
				parms[0] = "200";
				JSONObject jsob = new JSONObject();
				try {
					jsob.put("LottID", LOT_ID_LHC);
				} catch (JSONException ex) {
					Log.e("error", ex.toString());
				}
				parms[1] = jsob.toString();
				task.execute(parms);
			}
		}
	}

	String pl = "";
	
	class PLAsyncLoader extends AsyncTask<String, Integer, String> {// 继承AsyncTask
		public PLAsyncLoader() {
			super();
		}

		protected void onPreExecute() {
		}

		@Override
		protected String doInBackground(String... params) {
			String strResult;
			String action = params[0];
			strResult = GetRequestParams.getRequestResult(params[1], action, getApplicationContext());
			return strResult;
		}

		protected void onProgressUpdate(Integer... progress) {
		}

		protected void onPostExecute(String result) {
			if (result != null) {
				try {
					JSONTokener jsonParser = new JSONTokener(result);
					JSONObject js = (JSONObject) jsonParser.nextValue();
					if (Integer.parseInt(js.getString("Code")) == 0) {
						pl = ConvertJsonToList.getMap(js.getString("Data")).get("WinTypes").toString();
						plList = ConvertJsonToList.getList(pl);
					} else {
						Toast.makeText(SixFuckActivity.this, js.getString("Data"), Toast.LENGTH_SHORT).show();
					}
				} catch (JSONException ex) {
					Log.e("error", ex.toString());
					getIssue = true;
				} finally {
					getIssue = true;
				}
			} else {
			}
		}

		protected void onCancelled() {
			getIssue = true;
		}
	}
	
	
	private List<Map<String, Object>> mData;
	boolean getIssue = true;
	private Map<String, Object> cData;

	class AsyncLoader extends AsyncTask<String, Integer, String> {// 继承AsyncTask
		public AsyncLoader() {
			super();
		}

		protected void onPreExecute() {
		}

		@Override
		protected String doInBackground(String... params) {
			String strResult;
			String action = params[0];
			strResult = GetRequestParams.getRequestResult(params[1], action, getApplicationContext());
			return strResult;
		}

		protected void onProgressUpdate(Integer... progress) {
		}

		protected void onPostExecute(String result) {
			if (result != null) {
				try {
					JSONTokener jsonParser = new JSONTokener(result);
					JSONObject js = (JSONObject) jsonParser.nextValue();
					if (Integer.parseInt(js.getString("Code")) == 0) {
						mData = getData(result);
						for (int i = 0; i < mData.size(); i++) {
							int id = Integer.parseInt(mData.get(i).get("LotID").toString());
							cData = mData.get(i);
							switch (id) {
							case LOT_ID_LHC://
								lotID = LOT_ID_LHC;
								issueID = cData.get("IssueID").toString();
								issueName = cData.get("IssueName").toString();
								endTime = setEndTime(cData);
								strssqEndTime = cData.get("EndTime").toString();// 2014-05-10
								strssqEndTime = DateUtil.getDateTime4(strssqEndTime);// 2014-05-10
								buy_ssqxh_TextView01.setText(issueName);
								getCountDown(endTime);
								break;
							}
						}
					} else {
						Toast.makeText(SixFuckActivity.this, js.getString("Data"), Toast.LENGTH_SHORT).show();
					}
				} catch (JSONException ex) {
					Log.e("error", ex.toString());
					getIssue = true;
				} finally {
					getIssue = true;
				}
			} else {
			}
		}

		protected void onCancelled() {
			getIssue = true;
		}
	}

	private List<Map<String, Object>> getData(String strResult) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		try {
			JSONTokener jsonParser = new JSONTokener(strResult);
			JSONObject js = (JSONObject) jsonParser.nextValue();
			list = ConvertJsonToList.getList(js.getString("Data"));
		} catch (JSONException ex) {
		}
		return list;
	}

	private long setEndTime(Map<String, Object> data) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		long endTime = 0;
		try {
			long a = sdf.parse(data.get("CurrentTime").toString()).getTime();
			long b = sdf.parse(data.get("EndTime").toString()).getTime();
			endTime = (b - a) / 1000;
		} catch (ParseException e) {
		}
		return endTime;
	}
	class AsyncLoaderBuy extends AsyncTask<String, Integer, String> {// 继承AsyncTask
		String action;
		ShowTipDialog showdialog = new ShowTipDialog();
		protected void onPreExecute() {
			showdialog.showDialog(SixFuckActivity.this);
		}
		@Override
		protected String doInBackground(String... paramsArr) {
			String strResult = null;
			action = paramsArr[1];
			String UserID = ApplicationData.getInstance().getUserID();
			strResult = GetRequestParams.getRequestUserIDResult(paramsArr[0], UserID, action, getApplicationContext());
			return strResult;
		}
		protected void onProgressUpdate(Integer... progress) {
		}
		protected void onPostExecute(String result) {
			buy_ssqxh_Button05.setEnabled(true);
			if (result != null) {
				if (action.equals("207")) {
					Buy(result);
				}
				showdialog.closeDialog();
			} else {
				Toast.makeText(SixFuckActivity.this, getString(R.string.problem_01), Toast.LENGTH_LONG).show();
			}
		}
		protected void onCancelled() {
			buy_ssqxh_Button05.setEnabled(true);
		}
	}
	public void Buy(String strResult) {
		int buy_icon;
		try {
			JSONTokener jsonParser = new JSONTokener(strResult);
			JSONObject js = (JSONObject) jsonParser.nextValue();
			if (Integer.parseInt(js.getString("Code")) < 0) {
				buy_icon = R.drawable.buy_failure;
				String balanceNotFull = js.getString("Data");
					new ShowTipDialog().showBuyInfo(SixFuckActivity.this, balanceNotFull, "购买失败", buy_icon, dyn[0]);
			} else {
				buy_icon = R.drawable.buy_success;
				String msg = "";
				if ("-1".equals(issueName)) {
					msg = "发起六合彩" + " 购买方案\n\n我的认购：" + et_money.getText().toString() 
							+ "彩豆"+"\n方案编号："+js.getString("Data").toString();
				} else {
					msg = "发起六合彩" + issueName + "期购买方案\n\n我的认购：" 
				+ (et_money.getText().toString()) + "彩豆"+"\n方案编号："+js.getString("Data").toString();
				}
				if (!isFinishing()) {
					new ShowTipDialog().showBuyInfo(SixFuckActivity.this, msg, "投注成功", buy_icon, dyn[0]);
				}
				MyPreference.getInstance(this).storeBLotID(LotConstants.LOT_ID_LHC);
			}
		} catch (JSONException ex) {
			Log.e("error", ex.toString());
		}
	}
	@Override  
	public boolean dispatchTouchEvent(MotionEvent ev) {  
	    if (ev.getAction() == MotionEvent.ACTION_DOWN) {  
	        View v = getCurrentFocus();  
	        if (isShouldHideInput(v, ev)) {  
	            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  
	            if (imm != null) {  
	                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);  
	            }  
	        }  
	        return super.dispatchTouchEvent(ev);  
	    }  
	    // 必不可少，否则所有的组件都不会有TouchEvent了  
	    if (getWindow().superDispatchTouchEvent(ev)) {  
	        return true;  
	    }  
	    return onTouchEvent(ev);  
	}
	public  boolean isShouldHideInput(View v, MotionEvent event) {  
	    if (v != null && (v instanceof EditText)) {  
	        int[] leftTop = { 0, 0 };  
	        //获取输入框当前的location位置  
	        v.getLocationInWindow(leftTop);  
	        int left = leftTop[0];  
	        int top = leftTop[1];  
	        int bottom = top + v.getHeight();  
	        int right = left + v.getWidth();  
	        if (event.getX() > left && event.getX() < right  
	                && event.getY() > top && event.getY() < bottom) {  
	            // 点击的是输入框区域，保留点击EditText的事件  
	            return false;  
	        } else {  
	            return true;  
	        }  
	    }  
	    return false;  
	} 
}
